Ext.define('PJ.view.submittrainingplanviews.FillOpinions', {
	extend: 'AM.default.DefaultWindowForm',
	alias: ['widget.fillOpinions'],
	requires: ['AM.default.DefaultDateField', 
	           'AM.default.DateTime',
	           'AM.default.jsonp.DefaultSubmitJsonp',
	           'AM.default.DefaultDateField'
	           ],

	modal: true,// 开启不允许点击其他组件
	frame: true,
	notEdit: true,
	width: 650,
	height: 430,
	overflowY:'auto',
	layout: 'form',
	isSame: false,
	initComponent: function(){
    	var me = this;
    	me.items= [{
    		defaults: {
    			labelAlign: 'right',
    			labelWidth: 104,
    			columnWidth: .5,
    			padding:"9 0 0 0",
    			readOnly:me.isView
    		},
    		border: false,
    		xtype: "container",
    		width: 610,
    		//height:480,
    		layout: 'column',
    		allowBlank: false,
    		items: [{
		    	xtype: 'textareafield',
    			fieldLabel: '附加消息',
    			name: 'opinion',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: 1,
    			height: 46,
    			fieldStyle:'color:red' 
    		},{
    			xtype: 'textfield',
    			fieldLabel: '培训班名称',
    			name: 'classNameNew',
    			allowBlank: true,
    			readOnly:true,
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 50){
                			Orchid.alert('提示','该输入项最多输入50个字符！');
                		}
                	}
                },
                maxLength: 50
    		},{
    			xtype: 'textfield',
    			fieldLabel: '计划申请编号',
    			name: 'applyNumNew',
    			readOnly:true,
    			allowBlank: true
    			//emptyText: '请输入8位数字或字母',
    			//regex: /^[A-Za-z0-9]{1,8}$/,
    			//regexText: '计划申请编号只能输入8位长度的数字或字母！'
    		},{
    			xtype: 'textfield',
    			fieldLabel: '承办部委',
    			name: 'undertakeNameNew',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		},{
    			xtype: 'textfield',
    			fieldLabel: '合办部委',
    			name: 'jointNameNew',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		}/*,{
    			xtype: 'textfield',
    			fieldLabel: '计划时间',
    			name: 'planDateNew',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		}*/,{
    			xtype: 'textfield',
    			fieldLabel: '计划开始时间',
    			name: 'startPlanDateNewStr',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		},{
    			xtype: 'textfield',
    			fieldLabel: '计划结束时间',
    			name: 'endPlanDateNewStr',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		},{
    			xtype: 'textfield',
    			fieldLabel: '学制（天）',
    			name: 'planDayNew',
    			allowBlank: true,
    			readOnly:true,
    			columnWidth: .5
    		}, {
	        	xtype: 'container',
	        	columnWidth: 1,
	        	layout: 'column',
	        	id: 'classificationOpinions',
	        	itemId: 'classificationOpinions',
	        	defaults:{
					labelAlign: 'right',
	    			labelWidth: 104,
	    			columnWidth: 1,
	    			padding:"9 0 0 0",
	    			readOnly:me.isView
				},
	        	items: []
	        },{
    			xtype: 'hidden',
    			name: 'planIdNew'//培训班Id
    		}]
    	}];
		this.buttons = [{
			text:"无意见",
			scope:this,
			handler:function(btn){
				var win = btn.up("window");
				win.sub("noComments");
			}
		},{
			text:"提交意见",
			scope:this,
			handler:function(btn){
				var win = btn.up("window");
				win.sub("submit");
			}
		},{
			text: '取消',
			scope: this,
			handler: this.close
		}];
		this.callParent(arguments);
	},
	sub: function(flag){
		var me = this;
		var form = me.down('form');
		var baseForm = form.getForm();
		if (!baseForm.isValid()) {
			return;
		}
		var searchPlanId = baseForm.findField("planIdNew").getValue();
		var url = "";
		var opinionState = 1;
		if(flag=="noComments"){
			url = me.grid.store.saveUrl;
			opinionState = 2;
		}else if(flag=="submit"){
			url = me.grid.store.updateUrl;
		}
		var classificationOpinions = Ext.getCmp("classificationOpinions").items.items;
		var coIdArray = me.coArray;
		var opinionTitleCodes = new Array();
		var opinionTitleValues = new Array();
		var isHaveOpinions = true;
		for(i in classificationOpinions){
			if(classificationOpinions[i].getValue() != null && classificationOpinions[i].getValue() != ""){
				opinionTitleCodes.push(coIdArray[i].dataCode);
				opinionTitleValues.push(classificationOpinions[i].getValue());
				if(classificationOpinions[i].getValue() != null && classificationOpinions[i].getValue() != ""){
					isHaveOpinions = false;
				}
			}
		}
		if(isHaveOpinions && flag!="noComments"){
			Orchid.alert('提示','请至少填写一条意见！');
			return;
		}
		var params = {
				searchPlanId: searchPlanId,
				opinionTitleCodes: opinionTitleCodes,
				opinionTitleValues: opinionTitleValues,
				opinionState: opinionState
		};
		if(gj_onlineLearning_constant.loadType == "jsonp"){
			baseForm.doAction('submitJsonp',{
				submitEmptyText: false,//忽略emptyValue
				url: url,
				params: params,
				success: function(f, action){
					if (action.result.success) {
						Orchid.alert('消息', "操作成功!", function(){
							var gridPanel = me.grid;
							var store = gridPanel.getStore();
							store.reload();
							me.close();
						});
					}else{
						Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
							me.close();
						});
					}
				},
				failure: function(f, action){
					Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
				}
			});
		}else{
			form.submit({
				submitEmptyText: false,//忽略emptyValue
				url: url,
				params: params,
				success: function(f, action){
					if (action.result.success) {
						Orchid.alert('消息', "操作成功!", function(){
							var gridPanel = me.grid;
							var store = gridPanel.getStore();
							store.reload();
							me.close();
						});
					}else{
						Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
							me.close();
						});
					}
				},
				failure: function(f, action){
					Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
				}
			});
		}
	}
});